package com.beici.waterghost.service.qq;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.beici.waterghost.mapper.userMapper;
import com.beici.waterghost.model.idRandom;
import com.beici.waterghost.model.user;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * @auther WaterGhost
 * @date 2022/3/25 14:44
 */
@Service
public class login {
    @Autowired
    private userMapper userServer;
    @Autowired
    private BCryptPasswordEncoder bCryptPasswordEncoder;
    public long qqlogin(String openId,String userName,String userHeader){
        // 查询该账号是否注册
        Integer count = userServer.selectCount(new QueryWrapper<user>().eq("user_open_id", openId));
        if (count<=0){
            // 注册 后 返回id
            long id = idRandom.getLongRandom();
            userServer.qqlogin(openId,userName,userHeader,id,bCryptPasswordEncoder.encode("123"));
            return id;
        }
            //返回id
        user u = userServer.selectOne(new QueryWrapper<user>().eq("user_open_id", openId).select("user_phone"));
        Long userId = u.getUserPhone();
        return userId;

    }
}
